<%= form_for @site_config, url: admin_site_config_path(@site_config.var), method: 'patch' do |f| %>
  <%= render "/shared/error_messages", target: @site_config %>
  <div class="form-group">
    <label class="form-label">
      <%= @site_config.var %>
      <% if @site_config.require_restart? %>
        <span class="badge badge-warning">reboot required.</span>
      <% end %>
    </label>
    <%

    value = params.dig(:setting, :value) || Setting.send(@site_config.var)
    value = value.join("\n") if value.is_a?(Array)
    %>
    <% if @site_config.var == "timezone" %>
      <%= f.select :value, ActiveSupport::TimeZone.all.collect(&:name), { value: value }, { class: 'form-control' } %>
    <% elsif @site_config.var == "mailer_provider" %>
      <%= f.select :value, [["LetterOpener", "letter_opener"], ["SMTP", "smtp"],["PostMark", "postmark"]], { value: value }, { class: 'form-control' } %>
    <% else %>
      <% if @site_config.type == :boolean %>
        <label class="form-check">
          <%= f.check_box :value, checked: value, class: "form-check-input" %>
          <%= t("setting.#{@site_config.var}") %>
        </label>
      <% elsif @site_config.type == :integer %>
        <%= f.number_field :value, value: value, class: 'form-control' %>
      <% elsif @site_config.type == :hash %>
        <%= f.text_area :value, value: JSON.pretty_generate(value), class: 'form-control', rows: 15 %>
      <% else %>
        <%= f.text_area :value, value: value, class: 'form-control', rows: 15 %>
      <% end %>
    <% end %>
    <% if @site_config.type != :boolean %>
      <div class="form-text mt-2"><%= raw t("setting.#{@site_config.var}") %></div>
    <% end %>
  </div>
  <div class="form-actions flex col-md-6">
    <%= f.submit t("common.save"), class: "btn btn-primary", 'data-disable-with' => t("common.saving") %>
    <a href="<%= admin_site_configs_path %>" class="btn btn-secondary"><%= t("common.cancel") %></a>
  </div>
<% end %>
